package tests;
import common.Utils;
import org.openqa.selenium.By;

import java.io.IOException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 10715
 * Date: 2024-08-27
 * Time: 20:31
 */
public class NoLoginPage extends Utils {
    Class<?> targetclass = NoLoginPage.class;
    //主页
    String listUrl ="http://192.168.47.135:8653/blog_list.html";

    //编辑页
    String editUrl ="http://192.168.47.135:8653/blog_edit.html";
    //更新页
    String updateUrl="http://192.168.47.135:8653/blog_update.html?id=17";
    //详情页
    String detailUrl ="http://192.168.47.135:8653/blog_detail.html?id=17";

    public  static String url ="";
    public NoLoginPage() {
        super("");
    }
    public void listPageNoLogin(){
        driver.navigate().to(listUrl);
        String methodName ="";
        //没有弹窗，直接跳转登陆页
        driver.findElement(By.cssSelector("body > div.container-login > div"));
        try {
            methodName=targetclass.getMethod("listDetailNoLogin").getName();
            getScreenShot(targetclass.getName()+"-"+methodName);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        }

    }
    public void listDetailNoLogin(){
        driver.navigate().refresh();
        driver.navigate().to(detailUrl);
        String methodName ="";
        //没有弹窗，直接跳转登陆页
        driver.findElement(By.cssSelector("body > div.container-login > div"));
        try {
            methodName=targetclass.getMethod("listDetailNoLogin").getName();
            getScreenShot(targetclass.getName()+"-"+methodName);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        }
    }
    public void listUpdateNoLogin(){
        driver.navigate().refresh();
        driver.navigate().to(updateUrl);
        String methodName ="";
        //没有弹窗，直接跳转登陆页
        driver.findElement(By.cssSelector("body > div.container-login > div"));
        try {
            methodName=targetclass.getMethod("listUpdateNoLogin").getName();
            getScreenShot(targetclass.getName()+"-"+methodName);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        }
    }

    public void listEditNoLogin(){
        driver.navigate().refresh();
        driver.navigate().to(editUrl);
        String methodName ="";

        driver.findElement(By.cssSelector("#title")).sendKeys("你好");
        //弹出输入不合法，页面不变
        driver.findElement(By.cssSelector("#submit")).click();
        //
        driver.findElement(By.cssSelector("body > div.container-login > div"));
        try {
            methodName=targetclass.getMethod("listEditNoLogin").getName();
            getScreenShot(targetclass.getName()+"-"+methodName);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        }
    }


}